package com.sx.shop.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sx.shop.entity.Product;
import com.sx.shop.entity.User;
import com.sx.shop.service.ProductService;
import com.sx.shop.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController
{
    @Autowired
    private ProductService productService;
    @RequestMapping("/index")
    public String getIndex()
    {
        return "product_index";
    }
    //增加
    @RequestMapping("/add")
    @ResponseBody
    public String addProduct(Product product, HttpSession httpSession)
    {

       return productService.addProduct(product);
    }
    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public String deleteProduct(Integer proId){
        return productService.delete(proId);
    }
    //修改商品的基本信息
    @RequestMapping("/update")
    @ResponseBody
    public String updateProduct(Product product){
        return productService.updateInfo(product);
    }
    //修改绑定的
    @RequestMapping("/updateBind")
    @ResponseBody
    public String updateBind(Integer id,String ids)
    {
        return productService.updateBind(id,ids);
    }
    @RequestMapping("/all")
    @ResponseBody
    public ResultVo getAll(String keyword ,Integer page , Integer limit)
    {

        return (productService.getAll(keyword,page,limit));

    }
    @RequestMapping("/getList")
    @ResponseBody
    public List<Product> getList()
    {

        return productService.findAll();

    }
    @RequestMapping(value = "/{id}")
    @ResponseBody
    public Product getAll(@PathVariable("id") Integer id)
    {

       return productService.findById(id);

    }
}
